********************************************
*	Author: Rithika Kumar	               *
*   GOAL: Set up data for Figure A3        *
********************************************

* NOTE: Set path to "JOP Replication files" folder on your computer

clear
use "DATA FILES TO SHARE/main_ew_hh_df.dta", clear


 ************ CATCH UP CHECK **********
 
 set more off 
 *** we want to measure if the effect size between women in always migrant and tratment group in year one is significant 
 rename mob_score_norm mob
rename dec_score_norm dec_hh
rename pol_score_norm pol
rename GR_hh_cash cash
est clear

tab mig_status, nolabel

foreach i in mob cash dec_hh pol {
    reg `i' i.mig_husb EW_Age EW_child dil_dummy rel_hindu EW_edu i.GROUPS8 ASSETS5 FM1 i.DISTID if year == 0 & mig_status > 1, vce(cluster vill_id_num)
*** NOTE: I use the p-val for mig_husb in the regressions above to manually indicate the significance in Fig. A3
*** mob cash - significant at p<0.01 ***, dec_hh - significant at p-val<0.1 * and pol is not significant
tempfile alwaysw1_`i'
 margins i.mig_husb, saving("`alwaysw1_`i''")
}



use `alwaysw1_mob', clear
list
append using `alwaysw1_cash' `alwaysw1_dec_hh' `alwaysw1_pol'
gen Variable = .
replace Variable = 1 in 1/2
replace Variable = 2 in 3/4
replace Variable = 3 in 5/6
replace Variable = 4 in 7/8

label define dv 1 "Mobility" 2 "Access to Cash" 3 "Decision-Making" 4 "Political Index"  
label values Variable dv

gen year = 0

tempfile always_wave1
save `always_wave1'

use "DATA FILES TO SHARE/main_ew_hh_df.dta", clear


 
 set more off 
 *** we want to measure if the effect size between women in always migrant and tratment group in year one is significant 
 rename mob_score_norm mob
rename dec_score_norm dec_hh
rename pol_score_norm pol
rename GR_hh_cash cash
est clear


gen always_trt = 0 
replace always_trt = 1 if  w1_abshusband_dummy == 1 & w2_abshusband_dummy == 1


** now let us get the estimates in the second wave 
foreach i in mob cash dec_hh pol pol_disc{
 reg `i' i.always_trt EW_Age EW_child dil_dummy rel_hindu EW_edu i.GROUPS8 ASSETS5 FM1 i.DISTID if year == 1 & mig_status>1, vce(cluster vill_id_num)
 tempfile alwaysw2_`i'
margins i.always_trt, saving("`alwaysw2_`i''")
}


use `alwaysw2_mob', clear
list
append using `alwaysw2_cash' `alwaysw2_dec_hh' `alwaysw2_pol'
gen Variable = .
replace Variable = 1 in 1/2
replace Variable = 2 in 3/4
replace Variable = 3 in 5/6
replace Variable = 4 in 7/8

label define dv 1 "Mobility" 2 "Access to Cash" 3 "Decision-Making" 4 "Political Index"  
label values Variable dv

gen year = 1

tempfile always_wave2
save `always_wave2'

use `always_wave1', clear
append using `always_wave2'

rename _m1 group 
label define group 1 "Always Migrant" 0 "Wave 2 Migrants"  
label values group group

keep group _margin _se_margin _pvalue _ci_lb _ci_ub Variable year
rename (_ci_lb _ci_ub _margin _se_margin _pvalue) (cl cu mean se pval)

save "DATA FILES TO SHARE/TEMP_FILES/always_mig.dta", replace

